//
//  Created by Rene Dohan on 11/14/11.
//

#import "DSActivityView.h"
#import "PapRequest.h"
#import "TrafficController.h"

@implementation TrafficController

@dynamic impressionsRaw, impressionsUnique, clicksRaw, clicksUnique, salesApproved;
@dynamic salesPending, salesCostApproved, salesCostPending, commissionsApproved, commissionsPending;
@dynamic refundsApproved, refundsPending, chargeBacksApproved, chargeBacksPending;

- (void)loadData {
    PapRequest *request = [PapRequest new];
    request.action = @"trafic_overview";
    request.listener = self;
    [request send];
    [DSBezelActivityView newActivityViewForView:self.view];
}

- (void)onRequestData:(NSDictionary *)data {
    [DSActivityView removeView];
    NSLog(data.description);
    [self impressionsRaw].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"impressionsraw"]];
    [self impressionsUnique].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"impressionsunique"]];
    [self clicksRaw].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"clicksraw"]];
    [self clicksUnique].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"clicksunique"]];
    [self salesApproved].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"salesapproved"]];
    [self salesPending].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"salespending"]];
    [self salesCostApproved].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"salescostapproved"]];
    [self salesCostPending].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"salescostpending"]];
    [self commissionsApproved].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"commisionsapproved"]];
    [self commissionsPending].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"commisionspending"]];
    [self refundsApproved].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"refundsapproved"]];
    [self refundsPending].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"refundspending"]];
    [self chargeBacksApproved].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"chargebacksapproved"]];
    [self chargeBacksPending].text = [NSString stringWithFormat:@"%@", [data valueForKey:@"chargebackspending"]];
}

- (void)onRequestFailed {
    [DSActivityView removeView];
}

- (IBAction)onReloadClick:(UIButton *)sender {
    [self loadData];
}

- (IBAction)onTodayClick:(UIButton *)sender {

}

- (IBAction)onThisMonthClick:(UIButton *)sender {

}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self loadData];
}

@end